#region Usings

using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

#endregion

namespace SilverBox.Extensions
{
    public static class UIElementExtensions
    {
        public static WriteableBitmap GetBitmap(this UIElement obj, float scale)
        {
            var wBitmap = new WriteableBitmap(obj, new ScaleTransform {ScaleX = scale, ScaleY = scale});
            wBitmap.Render(obj, new ScaleTransform {ScaleX = scale, ScaleY = scale});
            return wBitmap;
        }

        public static string Serialize(this UIElement obj, float scale)
        {
            var writeableBitmap = obj.GetBitmap(scale);
            return writeableBitmap != null ? writeableBitmap.Serialize() : null;
        }
    }
}